package com.qfedu.labsystem.entity.vo;

import com.qfedu.labsystem.constant.SYSConstant;
import com.qfedu.labsystem.entity.enums.ResultEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @ClassName ResultOBJ
 * @Author ykx
 * @Date 2024/4/5 17:30
 * @Version 1.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "响应的VO对象", description = "封装接口返回给前端的数据")
public class ResultOBJ {
    /**
     * 状态码
     */
    @ApiModelProperty(value = "响应状态码", dataType = "int")
    private Integer code;

    /**
     * 消息
     */
    @ApiModelProperty(value = "响应提示信息", dataType = "msg")
    private String msg;

    /**
     * 返回的数据
     */
    @ApiModelProperty(value = "响应数据", dataType = "object")
    private Object data;

    public ResultOBJ(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultOBJ(Integer code) {
        this.code = code;
    }

    public ResultOBJ(ResultEnum resultEnum) {
        this.code = resultEnum.getCode();
        this.msg = resultEnum.getMsg();
    }

    public static ResultOBJ success(Object data) {
        ResultOBJ resultOBJ = new ResultOBJ(ResultEnum.SUCCESS);
        resultOBJ.setData(data);
        return resultOBJ;
    }

    public static ResultOBJ failed() {
        return new ResultOBJ(ResultEnum.FAILED);
    }

    public static ResultOBJ failed(Integer code, String msg) {
        return new ResultOBJ(code, msg);
    }

    public static ResultOBJ failed(String msg) {
        return new ResultOBJ(SYSConstant.CODE_ERROR, msg);
    }


    public static final ResultOBJ ADD_SUCCESS = new ResultOBJ(SYSConstant.CODE_SUCCESS, SYSConstant.ADD_SUCCESS);
    public static final ResultOBJ ADD_ERROR = new ResultOBJ(SYSConstant.CODE_ERROR, SYSConstant.ADD_ERROR);
    public static final ResultOBJ UPDATE_SUCCESS = new ResultOBJ(SYSConstant.CODE_SUCCESS, SYSConstant.UPDATE_SUCCESS);
    public static final ResultOBJ UPDATE_ERROR = new ResultOBJ(SYSConstant.CODE_ERROR, SYSConstant.UPDATE_ERROR);
    public static final ResultOBJ DELETE_SUCCESS = new ResultOBJ(SYSConstant.CODE_SUCCESS, SYSConstant.DELETE_SUCCESS);
    public static final ResultOBJ DELETE_ERROR = new ResultOBJ(SYSConstant.CODE_ERROR, SYSConstant.DELETE_ERROR);


}
